package com.lzy.arithmetic;

import java.util.HashMap;
import java.util.Map;

/**
 * Author: lzy
 * Date:   2020/06/09 11:34
 * Description:
 **/
public class 两数之和 {

    public static void main(String[] args) {
        boolean flag = false;
        int target = 11;
        int[] array = new int[]{5, 7, 3, 8, 9, 23, 6};
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < array.length; i++) {
            int other = target - array[i];
            if (map.containsKey(other)) {
                System.out.println("找到结果" + map.get(other) + "\t" + i);
                flag = true;
                break;
            } else {
                map.put(array[i], i);
            }
        }
        if (!flag) {
            System.out.println("没有找到结果");
        }
    }
}
